#ifndef _CMDLINE_H_
#define _CMDLINE_H_

#define CLI_MAX_CMD_LEN     64  /* 命令行长度 */
#define CLI_MAX_ARGS        16  /* 最大参数个数 */
#define CLI_MAX_CMDS        32  /* 最大允许定义的命令个数 */


typedef struct 
{
    unsigned int (*write)(const void *buf, unsigned int len);
    unsigned int (*read)(void *buf, unsigned int len);   
}cli_port_t;



typedef struct cli_obj {
    unsigned int (*write)(const void *buf, unsigned int len);
    unsigned int (*read)(void *buf, unsigned int len);
    void (*print)(struct cli_obj *this, const char *fmt, ...);
    char recvbuf[CLI_MAX_CMD_LEN + 1];
    unsigned short recvcnt;
    unsigned enable : 1;
}cli_obj_t;


typedef struct {
    char name[32];     /* 命令名 */
    int (*handler)(struct cli_obj *o, int argc, char *argv[]);  /* 命令处理函数 */
    char brief[128];  /* 命令简介 */
}cmd_item_t;

typedef struct cmd_manage
{
    int registerCmdNum;
    cmd_item_t cmd_item[CLI_MAX_CMDS];
}cmd_manage_t;

void cmd_manage_init(void);
int register_cmd(cmd_item_t *cmd);
int register_cmd_manage(cmd_item_t *cmd_item, int cmd_num);
void cli_init(cli_obj_t *obj, const cli_port_t *p);
void cli_enable(cli_obj_t *obj);
void cli_disable(cli_obj_t *obj);
void cli_exec_cmd(cli_obj_t *obj, const char *cmd);
void cli_process(cli_obj_t *obj);

int do_help(struct cli_obj *s, int argc, char *argv[]);




#endif



